package main

import "fmt"

/*
* Author: JacksonCoder
* CreateTime: 2025/5/19
 */
func testPipe(){
	pipe := make(chan int, 3)
	pipe <- 1
	pipe <- 2
	pipe <- 3
	var t1 int
	t1 = <- pipe
	fmt.Println("t1: ", t1)
}

func sum(s []int, c chan int){
	testPipe()
	sum := 0
	for _,v := range s{
		sum += v
	}
	fmt.Println("sum: ", sum)
	c <- sum // send sum to c
}

func main(){
	s := []int{7,2,5,1,6,9,8,3,4}
	c := make(chan int)
	go sum(s[:len(s)/2],c) //
	go sum(s[len(s)/2:],c) //
	// x ,y := <-c, <-c // receive from c
	x := <-c
	y := <-c
	fmt.Println("x = ",x," y = ",y)
}
